#include "spk_camera.h"
#include "utils.h"

void ip_addr_trans(string ip_str, u8 ip[4])
{
    struct in_addr var_ip;
    inet_pton(AF_INET, ip_str.c_str(), (void *)&var_ip);
    ip[0] = var_ip.s_addr & 0xFF;
    ip[1] = (var_ip.s_addr >> 8) & 0xFF;
    ip[2] = (var_ip.s_addr >> 16) & 0xFF;
    ip[3] = (var_ip.s_addr >> 24) & 0xFF;
}

string ip_addr_trans(u8 ip[4])
{
    string ip_str = std::to_string(ip[0]) + "." + std::to_string(ip[1]) + "." + std::to_string(ip[2]) + "." + std::to_string(ip[3]);
    return ip_str;
}

std::vector<std::string> split(std::string file, std::string pattern)
{
    std::string::size_type pos;
    std::vector<std::string> result;
    file += pattern; // 扩展字符串以方便操作
    int size = file.size();
    for (int i = 0; i < size; i++)
    {
        pos = file.find(pattern, i);
        if (pos < size)
        {
            std::string s = file.substr(i, pos - i);
            result.push_back(s);
            i = pos + pattern.size() - 1;
        }
    }
    return result;
}

int64_t getCurTimestamp() // 获取毫秒级时间戳（13位）
{
    return std::chrono::duration_cast<std::chrono::milliseconds>(
               std::chrono::system_clock::now().time_since_epoch())
        .count();
}
